package com.aiq.service.impl;

import com.aiq.constants.ConstantCode;
import com.aiq.dao.CommentMapper;
import com.aiq.exceptions.MyBaseException;
import com.aiq.pojo.Comment;
import com.aiq.service.CommentService;
import com.aiq.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @ClassName: CommentServiceImpl
 * @Description: 实现评论业务逻辑
 * @Author: vie0134
 * @Date: 2021-01-13 14:16
 * @Version: 1.0
 **/
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public R insert(Comment comment) {
        if (comment == null || StringUtils.isEmpty(comment)) {
            throw new MyBaseException("数据不为空", ConstantCode.DATA_NOT_TRANSFER);
        }
        try {
//            if (new Byte(comment.getType()) == 0) {
//                comment.getSongId();
//            } else {
//                comment.getSongListId();
//            }
            commentMapper.insert(comment);
            return R.setSuccess(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        throw  new MyBaseException("添加失败", ConstantCode.ERROR);
    }

    @Override
    public R update(Comment comment) {
        if (comment == null || StringUtils.isEmpty(comment)) {
            throw new MyBaseException("数据不为空", ConstantCode.DATA_NOT_TRANSFER);
        }
        try {

//            if (comment.getSongId() == 0) {
//                comment.setSongId(null);
//            } else {
//                comment.getSongId();
//            }
//            if (comment.getSongListId() == 0) {
//                comment.setSongListId(null);
//            } else {
//                comment.getSongListId();
//            }
            commentMapper.update(comment);
            return R.setSuccess(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        throw new MyBaseException("更改失败", ConstantCode.ERROR);
    }

    @Override
    public R delete(Integer id) {
        return null;
    }

    @Override
    public R selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public R allComment() {
        return null;
    }

    @Override
    public R commentOfSongId(Integer songId) {
        return null;
    }

    @Override
    public R commentOfSongListId(Integer songListId) {
        return null;
    }
}
